<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script type="application/javascript">
    var socket;
    if(window.WebSocket){
        socket = new WebSocket("ws://localhost:8899/ws");
        socket.onmessage = function (ev) {
            var ta = document.getElementById("responseText");
            ta.value = ta.value +'\n' + ev.data;
        }
        socket.onopen = function (ev) {
            var ta = document.getElementById("responseText");
            ta.value = "连接开启";
        }
        socket.onclose = function (ev) {
            var ta = document.getElementById("responseText");
            ta.value = ta.value + '\n' +"连接关闭";
        }
    }else {
        alert("不支持websockt")
    }
    function sendMsg (message){
        if(!window.WebSocket){
            return;
        }
        if(socket.readyState==WebSocket.OPEN){
            socket.send(message);
        }else {
            alert("websockt连接尚未准备完成")
        }
    }
</script>

<form onsubmit="return false">
    <textarea name="message" style="width: 400px;height: 200px"></textarea>
    <input type="button" value="发送数据" onclick="sendMsg(this.form.message.value)">
    <h1>服务器端输出</h1>
    <textarea id="responseText" style="width: 400px;height: 300px"></textarea>
    <input type="button" onclick="javascript:document.getElementById('responseText').value=''" value="清空内容">
</form>

</body>
</html>